<?php

namespace App\Transformers;

use App\Models\Address;
use Carbon\Carbon;
use League\Fractal\TransformerAbstract;

class AddressTransformer extends TransformerAbstract
{
    public function transform(Address $address)
    {
        $diff = Carbon::parse()->diffInMinutes($address->updated_at);

        return [
            'id' => $address->id,
            'mac_address' => $address->mac_address,
            'status' => $address->status,
            'online' => $diff > 5 ? 0 : 1,
            'note' => $address->note,
            'created_at' => $address->created_at,
            'updated_at' => $address->updated_at,
        ];
    }
}
